package listener;


import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

@WebListener()
public class SessionListener implements HttpSessionListener {
    private int userCount = 0;
    public SessionListener() {
    }

    public void sessionCreated(HttpSessionEvent se) {
        userCount++;
        se.getSession().getServletContext().setAttribute("userCount",userCount);
        /* Session is created. */
    }

    public void sessionDestroyed(HttpSessionEvent se) {
        userCount--;
        se.getSession().getServletContext().setAttribute("userCount",userCount);
        /* Session is destroyed. */
    }
}

